package com.sk.bilibili.service;

import com.sk.bilibili.bean.Member;
import com.sk.bilibili.property.BiliBiliProperty;
import com.sk.bilibili.utils.BSessionUtils;
import com.sk.bilibili.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 邵康
 * @date 2021/11/23 21:34
 */
@Service
public class LevelService {

    @Autowired
    private BiliBiliProperty biliBiliProperty;
    @Autowired
    private MemberService memberService;
    @Autowired
    private RedisUtils redisUtils;

    public void addExperience(int experience) {
        Member member = memberService.getById(BSessionUtils.getMemberId());
        Integer grade = member.getGrade();
        if(experience+member.getExperience()>=biliBiliProperty.getExperiences()[grade]){
            member.setExperience(experience+member.getExperience()-biliBiliProperty.getExperiences()[grade]);
            member.setGrade(grade+1);
            memberService.updateById(member);
        }else {
            redisUtils.changeNum(member,"experience",experience);
        }
    }

}
